package com.client.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.alibaba.fastjson.JSON;
import com.client.pojo.Categories;
import com.client.service.CategoriesService;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 词条分类表 前端控制器
 * </p>
 *
 * @author ckick
 * @since 2025-09-20 08:28:54
 */
@RestController
@RequestMapping("/categories")
public class CategoriesController {

    @Autowired
    private CategoriesService categoriesService;

    @PostMapping("/searchById")
    public String searchCategoryById(@RequestBody Map<String, Object> param) {
        // 获取id参数，不进行类型强制转换
        Object idObj = param.get("id");
        Integer categoryId = null;

        // 根据实际类型进行处理
        if (idObj instanceof Integer) {
            categoryId = (Integer) idObj;
        }
        return JSON.toJSONString(categoriesService.getById(categoryId));
    }

    @RequestMapping("list")
    public String getCategoriesList() {
        List<Categories> categoriesList = categoriesService.list();
        return JSON.toJSONString(categoriesList);
    }

}

